package com.liuh.service.impl;

import java.util.List;
import java.util.Map;

import com.liuh.dao.StuInfoDao;
import com.liuh.dao.impl.StuInfoDaoImpl;
import com.liuh.pojo.StuInfo;
import com.liuh.service.StudentService;
import com.liuh.util.Page;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;

public class StudentServiceImpl implements StudentService {

	StuInfoDao stuDao = new StuInfoDaoImpl();

	@Override
	public Page<StuInfo> findPageStu(Map<String, String> map) {
		// TODO Auto-generated method stub
		StuInfo stu = new StuInfo();
		stu.setClassesId(Convert.toInt(map.get("className"), 0));
		stu.setStuName(map.get("stuName"));
		// 分页参数
		int pageIndex = Convert.toInt(map.get("pageIndex"), 1);
		int pageSize = Convert.toInt(map.get("pageSize"), 10);
		//
		Page<StuInfo> page = new Page<>();
		page.setPageIndex(pageIndex);
		page.setPageSize(pageSize);
		page.setData(stuDao.selectStu(stu, pageIndex, pageSize, map));
		page.setTotalRow(stuDao.getDataCount(stu, map));
		return page;
	}

	@Override
	public int delStu(int id) {
		// TODO Auto-generated method stub
		return stuDao.delStu(id);
	}

	@Override
	public int delAllStu(Object[] ids) {
		// TODO Auto-generated method stub
		return stuDao.delAllStu(ids);
	}

	@Override
	public StuInfo findStuById(int id) {
		// TODO Auto-generated method stub
		StuInfo stu = new StuInfo();
		stu.setId(id);
		List<StuInfo> stus = stuDao.selectStu(stu, 1, 1, CollUtil.newHashMap());
		return stus.size() > 0 ? stus.get(0) : null;
	}

	@Override
	public int saveOrUpdate(StuInfo stu) {
		// TODO Auto-generated method stub
		return stu.getId() == 0 ? stuDao.addStu(stu) : stuDao.updStu(stu);
	}

}
